package com.czl.module_service.activity

import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.GsonUtils.fromJson
import com.blankj.utilcode.util.TimeUtils
import com.czl.base.base.BaseActivity
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.HealthReportBean
import com.czl.module_service.BR
import com.czl.module_service.R
import com.czl.module_service.databinding.ActivityFamilyHealthDetailBinding
import com.czl.module_service.databinding.ActivityHealthReportDetailBinding
import com.czl.module_service.viewmodel.FamilyHealthDetailViewModel
import com.google.gson.Gson
import java.util.*

@Route(path = AppConstants.Router.Service.F_FAMILY_HEALTH_DETAIL)
class FamilyHealthDetailActivity : BaseActivity<ActivityFamilyHealthDetailBinding, FamilyHealthDetailViewModel>() {

    lateinit var familyBean : HealthReportBean.FamilyData

    override fun initData() {
        viewModel.tvTitle.set("查看亲属信息")
        familyBean = intent.getSerializableExtra("data") as HealthReportBean.FamilyData
        val viewBinding: ActivityFamilyHealthDetailBinding = binding
        viewBinding.tvRelationType.text = if (familyBean.relativesType == 0) "配偶" else if (familyBean.relativesType == 1) "父母" else if (familyBean.relativesType == 2) "子女" else "其他"
        viewBinding.tvRelationName.text = familyBean.relativesName
        viewBinding.tvRelationIdCard.text = familyBean.relativesCard
        viewBinding.tvRelationPhone.text = familyBean.relativesPhone
        viewBinding.tvRelationTemp.text = familyBean.temperature + " ℃"
        if (familyBean.healthyType == 0) {
            viewBinding.tvRelationHealthyType.text = "健康"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.GONE
        }
        if (familyBean.healthyType == 4) {
            viewBinding.tvRelationHealthyType.text = "已治愈"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.GONE
        }
        if (familyBean.healthyType == 5) {
            viewBinding.tvRelationHealthyType.text = "其他"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.GONE
        }
        if (familyBean.healthyType == 1) {
            viewBinding.tvRelationHealthyType.text = "发热"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.VISIBLE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.GONE
            if (familyBean.admitted == 1) viewBinding.tvRelationIsShouZhi.text = "是" else viewBinding.tvRelationIsShouZhi.text = "否"
        }
        if (familyBean.healthyType == 2) {
            viewBinding.tvRelationHealthyType.text = "疑似"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.VISIBLE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.GONE
            if (familyBean.admitted == 1) viewBinding.tvRelationIsShouZhi2.text = "是" else viewBinding.tvRelationIsShouZhi2.text = "否"
            viewBinding.tvRelationSuspected.text = familyBean.suspected
        }
        if (familyBean.healthyType == 3) {
            viewBinding.tvRelationHealthyType.text = "确诊"
            findViewById<LinearLayout>(R.id.ll_visibility1).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility2).visibility = View.GONE
            findViewById<LinearLayout>(R.id.ll_visibility3).visibility = View.VISIBLE
            if (familyBean.admitted == 1) viewBinding.tvRelationIsShouZhi3.text = "是" else viewBinding.tvRelationIsShouZhi3.text = "否"
            if (familyBean.confirmed == 1) viewBinding.tvRelationConfirmed.text = "轻度" else viewBinding.tvRelationConfirmed.text = "重度"
        }
        if (familyBean.touching == 0) {
            viewBinding.tvRelationTouch.text = "否"
            findViewById<LinearLayout>(R.id.ll_visibility4).visibility = View.GONE
        } else {
            viewBinding.tvRelationTouch.text = "是"
            findViewById<LinearLayout>(R.id.ll_visibility4).visibility = View.VISIBLE
            viewBinding.tvRelationTouchTime.text = TimeUtils.date2String(
                Date(familyBean.touchingTime.toLong()),
                "yyyy-MM-dd"
            )
            viewBinding.tvRelationTouchName.text = familyBean.touchingName
            viewBinding.tvRelationTouchPhone.text = familyBean.touchingPhone
        }
    }

    override fun initContentView(): Int {
        return R.layout.activity_family_health_detail
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }
}